package test;

import static org.junit.Assert.assertEquals;

import hospital.*;

import java.util.ArrayList;

import movement.Location;

import org.junit.*;


public class testHospitalBoard {

	HospitalBoard hospitalBoard;
	Hospital hospitalAddTwice;

	@Before
	public void setUp() throws Exception {
		// hospLoc = new Location(20,20,"HospLocation");
		hospitalBoard = new HospitalBoard();
		hospitalAddTwice = new Hospital("HospitalAddTwice", new Location(100,150,"DoubleTime"));
		hospitalBoard.addHospital(hospitalAddTwice);
	}
	
	@Test (expected=IllegalArgumentException.class) 
	public void testAddExistingHospital(){ // also tests canAddToHospitalBoard
		hospitalBoard.addHospital(hospitalAddTwice);
	}

	@Test
	public void testAddHospital(){
		assertEquals(hospitalBoard.getHospitalsClone().size(),1);
		hospitalBoard.addHospital(new Hospital("Sint-jozef", new Location(40,50,"Kessel-lo"))); 
		assertEquals(hospitalBoard.getHospitalsClone().size(),2);
		hospitalBoard.addHospital(new Hospital("Sint-jozef 2", new Location(45,50,"Kessel-lo 2")));
		assertEquals(hospitalBoard.getHospitalsClone().size(),3);
	}
	
	@Test (expected=IllegalArgumentException.class) 
	public void testAddHospitalEmptyName(){ // also tests canAddToHospitalBoard
		hospitalBoard.addHospital(new Hospital("", new Location(10,10,"Jap")));	
	}
	
	@Test (expected=IllegalArgumentException.class) 
	public void testAddHospitalNullName(){ // also tests canAddToHospitalBoard
		hospitalBoard.addHospital(new Hospital(null, new Location(10,10,"Jap")));
	}
	
	@Test (expected=IllegalArgumentException.class) 
	public void testAddNullHospital(){ // also tests canAddToHospitalBoard
		hospitalBoard.addHospital(null);
	}

	@Test
	public void testConstructor(){
		HospitalBoard hospi = new HospitalBoard();
		assertEquals(0,hospi.getHospitalsClone().size());
	}

	@Test
	public void testGetHospitalByLocation() {
		Location baseLocation = new Location(-10, 20, "Base");
		Hospital h1 = new Hospital("Hospital1", new Location(10, 10,
				"Location1"));
		Hospital h2 = new Hospital("Hospital2",
				new Location(0, 10, "Location2"));
		Hospital h3 = new Hospital("Hospital3", new Location(20, 10,
				"Location3"));
		Hospital h4 = new Hospital("Hospital4", new Location(40, 10,
				"Location4"));
		hospitalBoard.addHospital(h1);
		hospitalBoard.addHospital(h2);
		hospitalBoard.addHospital(h3);
		hospitalBoard.addHospital(h4);

		// ask , based on distance from given location
		ArrayList<Hospital> result = hospitalBoard.getHospitals(baseLocation);
		assertEquals(result.get(0).getName(), h2.getName());
		assertEquals(result.get(1).getName(), h1.getName());
		assertEquals(result.get(2).getName(), h3.getName());
		assertEquals(result.get(3).getName(), h4.getName());
	}
	
	@Test
	public void testGettersAndSetters() {
		assertEquals(hospitalBoard.getHospitalsClone().size(), 1);
		
		Hospital h1 = new Hospital("Hospital1", new Location(10, 10,
				"Location1"));
		Hospital h2 = new Hospital("Hospital2",
				new Location(0, 10, "Location2"));

		hospitalBoard.addHospital(h1);
		hospitalBoard.addHospital(h2);

		assertEquals(hospitalBoard.getHospitalsClone().size(), 3);
	}
}
